package com.example.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
    private Context context;
    public MyAdapter(Context context){
        super();
        this.context = context;
    }
    private int[] imageld = {R.drawable.icon_weather, R.drawable.icon_shopping, R.drawable.icon_security, R.drawable.icon_agriculture};
    private int[] colorld = {R.color.main_blue0, R.color.main_orange, R.color.main_orangered, R.color.main_blue};
    private String[] stringld = {"环境气象","智能商超","预警信息","智能农场"};


    @Override
    public int getCount() {
        return imageld.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHoller v = null;
        if (convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.items,null);
            v = new viewHoller();
            v.IITitle =(LinearLayout)convertView.findViewById(R.id.IITitle);
            v.imgTitle = (ImageView)convertView.findViewById(R.id.imgTitle);
            v.tvTitle = (TextView)convertView.findViewById(R.id.tvTitle);
            convertView.setTag(v);
        }else{
            v = (viewHoller) convertView.getTag();
        }
    v.IITile.setBackgroundResource(colorld[position]);
        v.imgTitle.setImageResource(imageld[position]);
        v.tvTitle.setText(stringld[position]);
        return convertView;
    }
}


